<!DOCTYPE html>
<html>
<title>JavaScript if 条件语句示例 - 基础教程(cainiaojc.com)</title>

<body>
    <h1>JavaScript if 语句</h1>
    <p>仅当变量x的值小于0时,单机按钮以显示负</p>
    <button onclick="mygo()">soya</button>
    <p id="result"></p>

    <h1>JavaScript if...else 语句</h1>
    <p>单击按钮以显示消息，如果变量x的值小于0，则打印"负"，否则显示"正"：</p>
    <button onclick="avemujica()">saki</button>
    <p id="request"></p>

    <p>图片的转变</p>
    <img id="demo" onclick="crychic()" src="/run/images/avatar-female.jpg" width="180" height="180">
    <p>在此示例中，我们首先检查最高得分，该得分将大于或等于90。之后，else if语句将检查大于80、70和60，直到达到默认的else。 成绩不及格：</p>


    <p>JavaScript 三元运算符示例 - 基础教程(cainiaojc.com)</p>
    <p>在输入框中输入您的年龄:</p>
    <input type="number" id="gbc" value="20">
    <button type="button" onclick="jqrc()">jqrc</button>
    <p id="PWP"></p>

    <script>
        function mygo() {
            var x = -4;
            if (x < 0) {
                document.getElementById("result").innerHTML = "永不oTL";
            }
        }


        function avemujica() {
            var x = -4;
            var msg;

            if (x < 0) {
                msg = "客服"
            } else {
                msg = "打工"
            }

            document.getElementById("request").innerHTML = msg;
        }


        function crychic() {
            var image = document.getElementById("demo");
            if (image.src.match("female")) {
                image.src = "/run/images/avatar-male.jsp";
            } else {
                image.src = "/run/images/avatar-female.jpg";
            }
        }


        var grade = 80;
        if (grade >= 90) {
            document.write("A");
        } else if (grade >= 80) {
            document.write("B");
        } else if (grade >= 70) {
            document.write("C");
        } else if (grade >= 60) {
            document.write("D");
        } else {
            document.write("F");
        }


        function jqrc() {
            var age = document.getElementById("gbc").value;
            var status = (age >= 18) ? "adult" : "minor";
            document.getElementById("PWP").innerHTML = status;
        }
    </script>
</body>

</html>